﻿using Modules.Units;
using RabbitMQ.Client;
using System;
using System.Collections.Generic;
using System.Text;

namespace RabbitMQ
{
    public  class MQHelperFactory
    {

        static IConnection connection;
        static IModel channel;
        static string exchangeName;
        private static ConnectionFactory connectionFactory;
        /// <summary>
        /// 构造通讯连接选项
        /// </summary>
        /// <returns></returns>
        public static IConnectionFactory ClientOptionBuilder()
        {

            //创建连接工厂
            connectionFactory = new ConnectionFactory
            {
                HostName = AppsettingUnits.rabbitMq.Server,
                UserName = AppsettingUnits.rabbitMq.UserName,
                Password = AppsettingUnits.rabbitMq.Password,
            };
            //创建连接
            connection = connectionFactory.CreateConnection();
            //创建通道
            channel = connection.CreateModel();
            return connectionFactory;
        }

        public static RabbitMQHelper Sorting() => new RabbitMQHelper(channel,"Sorting");

        public static  RabbitMQHelper SortingView() => new RabbitMQHelper(channel,"SortingView");
    }
}
